package com.jsoft.jsofted.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.binding.annotation.BindDict;
import com.diboot.core.binding.annotation.BindEntityList;
import com.diboot.core.binding.annotation.BindField;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import com.jsoft.jsofted.framework.entity.OfOrgEntity;
import com.jsoft.jsofted.platform.entity.RoleEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 人员信息表
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Table("sys_user")
@TableName("sys_user")
public class UserEntity extends OfOrgEntity {

    /**
     * 真实姓名：
     */
    @Column(length = 64)
    @IsNotNull
    protected String name;

    /**
     * 电话号码：可以作为登录账号使用，系统唯一
     */
    @Column(length = 32)
    @IsNotNull
    @Unique(value = "tel", columns = {"tenant_id", "tel"})
    protected String tel;

    /**
     * 来自字典数据 DicData.sexTypes
     */
    @Column
    @IsNotNull
    protected String sex;

    @TableField(exist = false)
    @BindDict(type = "USER_SEX", field = "sex")
    protected String sexName;

    /**
     * 登录账号：为避免和手机号冲突，登录账号必须以字母开头，唯一
     */
    @Column(length = 32)
    @Unique(value = "username", columns = {"tenant_id", "username"})
    protected String username;

    /**
     * 登录密码：
     */
    @Column(length = 32)
    protected String password;

    // 主要职位（岗位）
    @Column
    protected Long postId;

    @TableField(exist = false)
    @BindField(entity = PostEntity.class, field = "name", condition = "post_id=id")
    protected String postName;

//    @TableField(exist = false)
//    @BindEntityList(entity = PostEntity.class, condition = "this.id=sys_user_post.user_id AND sys_user_post.post_id=id")
//    protected List<PostEntity> postList;

    @TableField(exist = false)
    @BindEntityList(entity = UserPostEntity.class, condition = "id=user_id")
    protected List<UserPostEntity> userPostList;

    @TableField(exist = false)
    @BindEntityList(entity = RoleEntity.class, condition = "this.id=sys_user_role.user_id AND sys_user_role.role_id=id")
    protected List<RoleEntity> roleList;

    @TableField(exist = false)
    @BindEntityList(entity = UserRoleEntity.class, condition = "id=user_id")
    protected List<UserRoleEntity> userRoleList;

}
